#ifndef PD_DEFINE_H_
#define PD_DEFINE_H_

#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <sys/syscall.h>

#ifdef __cplusplus
# define PD_CPP_START extern "C" {
# define PD_CPP_END }
#else
# define PD_CPP_START
# define PD_CPP_END
#endif

#ifndef UNUSED
#define UNUSED(v) ((void)(v))
#endif

#define GETTID() syscall(__NR_gettid)

#define MAX_SOCKET_EVENTS 256

struct PdSocket;
typedef struct PdSocket PdSocket;

struct PdTransport;
typedef struct PdTransport PdTransport;

struct PdIOComponent;
typedef struct PdIOComponent PdIOComponent;

typedef void (*pd_on_readable_pt) (PdIOComponent *ioc);
typedef void (*pd_on_writeable_pt) (PdIOComponent *ioc);
typedef void (*pd_on_error_pt) (PdIOComponent *ioc);

struct PdIOComponent
{
    PdSocket *sock;
    PdTransport *ts;
    pd_on_readable_pt on_readable;
    pd_on_writeable_pt on_writeable;
    pd_on_error_pt on_error;
    PdIOComponent *next;
};

extern PdIOComponent *pd_ioc_alloc();

extern void pd_ioc_free(PdIOComponent *ioc);

#endif

